<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/request.css" media="all" />
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/wxmsg.css" media="all" />
<script type="text/javascript"  src="<{$ipath}>public/js/head.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/jquery.min.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/ajaxfileupload.js"></script>
<script>
$(function(){
	$("#sendtype").change(function(){
		$(this).nextAll("span").hide();
		var type=$("#sendtype").val();
		if(type==2 || type=='2'){
			$(this).next("span").show();
		}else if(type==3 || type=='3'){
			$(this).next().next("span").show();
		}else{
			return false;
		}
	});
});
function showwxput(n){
	for(var i=1;i<6;i++){
		$("#putcon"+i).hide();
		$(".ptit i").removeClass("select");
	}
	var temarr=new Array();
	temarr[1]="txt";
	temarr[2]="img";
	temarr[3]="voice";
	temarr[4]="video";
	temarr[5]="news";
	$("#putcon"+n).show();
	$("#type").val(n);
	$("."+temarr[n]+"icon i").addClass("select");
}

function checkfrm(){
	var type = $("#type").val();
	if(type==1){
		if($("#content").val()=='' || $("#content").val()==null){
			alert('请填写自动回复内容');
			return false;
		}else{
			return true;
		}
	}else if(type==3){
		if($("#title").val()=='' || $("#title").val()==null){
			alert('请填写语音标题');
			return false;
		}else{
			return true;
		}
	}else if(type==4){
		if($("#tit").val()=='' || $("#tit").val()==null){
			alert('请填写视频标题');
			return false;
		}else if($("#desc").val()=='' || $("#desc").val()==null){
			alert('请填写视频描述');
			return false;
		}else{
			return true;
		}
	}
}
function delwxrequest(id,type){
	var url='?g=wx&m=weixin&a=delmedia&id='+id;
	$.get(url,function(data){
		if(data=='' || data==null){
			alert('删除失败，请重试');
			return false;
		}
		if(data.error==1000 || data.error=='1000'){
			$("#putcon"+type).children(".request_item").html('');
			$("#putcon"+type).children(".request_add").show();
		}
	},'json');
}
function showwxrequest(type){
	$("#putcon"+type).children("div").eq(0).show();
	$("#putcon"+type).children("div").eq(1).hide();
}
function showconmode(n){
	if(n==1){
		$("#menu_con_url").hide();
		$("#menu_con_event").show();
	}else if(n==2){
		$("#menu_con_url").show();
		$("#menu_con_event").hide();
	}else{
		return false;
	}
}
function save_smart(n,fname){
	var url='?g=wx&m=weixin&a=savesmart';
	var data={};
	data.type = n;
	if(n==3){
		data.title = $("#vtit").val();
	}else if(n==4){
		data.title = $("#tit").val();
		data.desc = $("#desc").val();
	}
	if(n>1){
		$.ajaxFileUpload({
			url:url,
			dataType:'json',
			fileElementId:fname,
			type:'post',
			secureuri:false,
			data:data,
			success:function(data){
				if(data.error==1000 || data.error=='1000'){
					if(data.type==2 || data.type=='2'){
						$("#putcon2 .request_item").html('<li><img src="'+data.msg+'" style="max-width:300px" /><input type="hidden" name="media_id2" value="'+data.media_id+'" /><a onClick="delwxrequest('+data.mid+',2)">删除图片</a></li>');
						$("#putcon2 .request_add").hide();
					}
					if(data.type==3 || data.type=='3'){
						$("#putcon3 .request_item").html('<li><audio controls src="'+data.msg+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id3" value="'+data.media_id+'" /><a onClick="delwxrequest('+data.mid+',3)">删除语音</a></li>');
						$("#putcon3 .request_add").hide()
					}
					if(data.type==4 || data.type=='4'){
						$("#putcon4 .request_item").html('<li><video width="300" controls src="'+data.msg+'">您的浏览器不支持H5视频播放</video><input type="hidden" name="media_id4" value="'+data.media_id+'" /><a onClick="delwxrequest('+data.mid+',4)">删除视频</a></li>');
						$("#putcon4 .request_add").hide()
					}
				}else{
					alert(data.msg);
					return false;
				}
			},
		});
	}else{
		return false;
	}
}
</script>
<style>.topnav{ width:94%;margin:0 auto;padding-top:16px;font-size:14px;line-height:18px;}.topnav *{color:#333;}</style>
</head>

<body>
<div class="topnav"><a class="level-1" href="?g=index&m=index&a=platform">我的服务</a>><a class="level-2" href="?g=index&m=index&a=wxpla">微信公众号</a>><span class="level-3">群发功能</span></div>
<div class="wxmsg">
<form action="?g=wx&m=weixin&a=sendwxmsg" method="post" target="hiddfrm">
    <h1>群发功能</h1>
    <ul class="nav"><li class="select">新建群发消息</li><li><a href="?g=wx&m=weixin&a=sendlist">已发送消息</a></li><em>群发消息规则说明</em></ul>
    <ul class="putinfo">为保障用户体验，微信公众平台严禁恶意营销以及诱导分享朋友圈，严禁发布色情低俗、暴力血腥、政治谣言等各类违反法律法规及相关政策规定的信息。一旦发现，我们将严厉打击和处理。</ul>
    <div class="sendmsg">
        <ul class="senduser">群发对象：<select id="sendtype" ><option value="1" selected>全部粉丝</option><option value="2">分组群发</option><!--<option value="3">指定粉丝</option>--></select> <span>选择粉丝分组：<select name="groupid"><{section name=l loop=$wxgroup}><option value="<{$wxgroup[l].id}>"><{$wxgroup[l].name}></option><{/section}></select></span> <span>输入粉丝名称：<input name="fenname" id="fenname" value=""/> <input type="button" name="fenlist" value="选择粉丝" class="wxbutton" style="margin-top:0px" /> </span></ul>
    </div>
    <div class="wxinput">
        <ul class="ptit">
        <li class="txticon"><a onClick="showwxput(1)"><i class="icon select"></i><span>文字</span></a></li>
        <li class="imgicon"><a onClick="showwxput(2)"><i class="icon"></i>图片</a></li>
        <li  class="voiceicon"><a onClick="showwxput(3)"><i class="icon"></i>语音</a></li>
        <li  class="videoicon"><a onClick="showwxput(4)"><i class="icon"></i>视频</a></li>
        <li  class="newsicon"><a onClick="showwxput(5)"><i class="icon"></i>图文</a></li>
        </ul>
        <ul class="pcon" id="putcon1" style="display:block"><textarea name="content" id="content"></textarea></ul>
        <ul class="pcon" id="putcon2">
        <div class="request_item"></div>
        <div class="request_add">
            <li class="selmate">
                <a onClick="getmedialist(2)"><i></i>
                <h2 class="space_bottom">从素材库选择</h2></a>
            </li>
            <li class="selmate">
                <i><input type="file" name="img" id="img" class="fhidden" /></i>
                <h2 class="space_bottom">本地图片</h2>
            </li>
            <h5><input type="button" value="添加本地图片" onClick="save_smart(2,'img')" class="wxsubmit" /></h5>
        </div>
  
        </ul>
        <ul class="pcon" id="putcon3">
        <div class="request_item"></div>
        <div class="request_add">
            <li class="selmate">
                <a onClick="getmedialist(3)"><i></i>
                <h2 class="space_bottom">从素材库选择</h2></a>
            </li>
            <li class="selmate">
                <i><input type="file" name="voice" id="voice" class="fhidden" /></i>
                <h2>本地语音</h2>
                <dd style="margin-bottom:30px;">语音标题：<input type="text" placeholder="请输入语音文件标题" id="vtit" name="vtit" /></dd>
            </li>
            <h5><input type="button" value="添加本地语音" onClick="save_smart(3,'voice')" class="wxsubmit" /></h5>
        </div>
        	
        </ul>
        <ul class="pcon" id="putcon4">
        <div class="request_item"></div>
        <div class="request_add">
        <li class="selmate">
                <a onClick="getmedialist(4)"><i></i>
                <h2 class="space_bottom">从素材库选择</h2></a>
            </li>
            <li class="selmate">
                <i><input type="file" name="video" id="video" class="fhidden" /></i>
                <h2>本地视频</h2>
                <dd>视频标题：<input type="text" placeholder="请输入视频文件标题" name="tit" id="tit" /></dd>
                <dd style="margin-bottom:5px;">视频说明：<input type="text" placeholder="请输入视频文件简介" name="desc" id="desc" /></dd>
            </li>
            <h5><input type="button" value="添加本地视频" onClick="save_smart(4,'video')" class="wxsubmit" /></h5>
        </div>
        	
        </ul>
        <ul class="pcon" id="putcon5">
        <div class="request_item"></div>
        <div class="request_add">
        <li class="selmate">
                <a onClick="getmedialist(5)"><i></i>
                <h2 class="space_bottom">从素材库选择</h2></a>
            </li>
            <li class="selmate">
                <a href="?g=wx&m=weixin&a=wxnews" target="_blank"><i></i>
                <h2 class="space_bottom">新建图文消息</h2></a>
            </li>
        </div></ul>
    </div>
    <div><input type="hidden" id="type" name="type" value="1" /><input type="submit" class="wxbutton" value="确认群发" /></div>
</form>
</div>
<div id="shade"></div>
<div id="showmedialist" class="hidddiv">
	<h3>选择素材<em onClick="closeshowmedialist()"><i class="icon_close"></i></em></h3>
    <ul id="showimglist"></ul>
    <ul id="showvoicelist"></ul>
    <ul id="showvideolist"></ul>
    <ul id="shownewslist"></ul>
    <h4><input type="hidden" id="mediashowid" value="" /><input type="hidden" id="mediashowurl" value="" /><input type="hidden" id="selbytype" value="" /><input type="hidden" id="mediashowtomore" value="" /><input type="button" class="wxbutton_cancel" id="mediashowsetbutton" value="确认"> <input type="button" class="wxbutton_cancel" onClick="closeshowmedialist()" value="取消" /></h4>
</div>
<script>
function getmedialist(n){
	var url;
	var type;
	var str='';
	var temp='';
	if(n==2){
		type='img';
	}else if(n==3){
		type='voice';
	}else if(n==4){
		type='video';
	}else if(n==5){
		type='news';
	}else{
		alert('选择素材类型错误');
		return false;
	}
	$("#selbytype").val(n);
	url='?g=wx&m=weixin&a=getmedialist&type='+type;
	$.get(url,function(data){
		if(data=='' || data==null){
			str+='<li class="showmedia_nono">暂时没有素材</li>';
		}else{
			if(n==2){
				for(ritem in data){
					str+='<li class="showmedia_img" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="'+data[ritem].url+'" width="120" height="120" /></li>';
				}
			}else if(n==3){
				for(ritem in data){
					str+='<li class="showmedia_voice" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="<{$ipath}>wx/images/voice_stop.png" width="60px" onclick="playaudio(this)" /><audio src="'+data[ritem].url+'"></audio>'+data[ritem].title+'</li>';
				}
			}else if(n==4){
				for(ritem in data){
					str+='<li class="showmedia_video" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><video src="'+data[ritem].url+'" controls width="200"></video><br>'+data[ritem].title+'<br>'+data[ritem].content+'</li>';
				}
			}else if(n==5){
				for(ritem in data){
					str+='<li class="showmedia_news" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><dl><img src="'+data[ritem].url+'" width="100%"><dd>'+data[ritem].ntitle+'</dd></dl></li>';
				}
			}
			$("#show"+type+"list").append(str);
			$("#shade").show();
			$("#showmedialist").show();
			$("#show"+type+"list").show();
		}
	},'json');
}
function playaudio(obj){
	if($(obj).next("audio").get(0).paused){
		$(obj).next("audio").get(0).play();
		$(obj).attr("src","<{$ipath}>wx/images/voice_play.gif");
	}else{
		$(obj).next("audio").get(0).pause();
		$(obj).attr("src","<{$ipath}>wx/images/voice_stop.gif");
	}
}
function closehidd(){
	$(".hidddiv").hide();
	$("#shade").hide();
}
function setmediashowid(mid,url,obj){
	$("#mediashowid").val(mid);
	$("#mediashowurl").val(url);
	$("#mediashowsetbutton").attr("class","wxbutton");
	$("#mediashowsetbutton").attr("onclick","setmedia()");
	$(obj).parent().find(".icon_issel").remove();
	$(obj).append('<i class="icon_issel"></i>');
	if($(obj).find("dd").length>0){
		$("#mediashowtomore").val($(obj).find("dd").html());
	}
	
}
function setmedia(){
	var type = $("#selbytype").val();
	var media_id=$("#mediashowid").val();
	var url=$("#mediashowurl").val();
	if(type==2){
		$("#putcon2 .request_item").html('<img src="'+url+'" style="max-width:300px" /><input type="hidden" name="media_id2" value="'+media_id+'" /><a onclick="delmedia(this)">删除素材</a>');
		$("#putcon2 .request_add").hide();
		$("#putcon2 .addbutton").hide();
	}else if(type==3){
		$("#putcon3 .request_item").html('<audio controls src="'+url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="medi3a_id" value="'+media_id+'" /><a onclick="delmedia(this)">删除素材</a>');
		$("#putcon3 .request_add").hide();
		$("#putcon3 .addbutton").hide();
	}else if(type==4){
		$("#putcon4 .request_item").html('<video width="300" controls src="'+url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="media_id4" value="'+media_id+'" /><a onclick="delmedia(this)">删除素材</a>');
		$("#putcon4 .request_add").hide();
		$("#putcon4 .addbutton").hide();
	}else if(type==5){
		var title = $("#mediashowtomore").val();
		$("#putcon5 .request_item").html('<dl><img src="'+url+'" width="100%" /><dd>'+title+'</dd></dl><input type="hidden" name="media_id5" value="'+media_id+'" /><a onclick="delmedia(this)">删除素材</a>');
		$("#putcon5 .request_add").hide();
		$("#putcon5 .setbutton").show();
	}
	closeshowmedialist();
}
function closeshowmedialist(){
	$("#shade").hide();
	$("#showmedialist").hide();
	$("#mediashowsetbutton").attr("onclick",'');
	$("#mediashowsetbutton").attr("class","wxbutton_cancel");
	$("#showmedialist").children("ul").html('');
	$("#showmedialist").children("ul").hide();
}
function delmedia(obj){
	$(obj).parent().parent().find(".request_add").show();
	$(obj).parent().html('');
}
</script>
<iframe width="0" height="0" name="hiddfrm" id="hiddfrm" scrolling="no" frameborder="0" style="display:none"></iframe>
</body>
</html>
